<?php

/** 
 * @author Nguyen
 * 
 */
class ControllerFactory {
	const PREFIX = 'Controller';
	
	private $_context;
	/**
	 */
	function __construct() {
		
	}
	/**
	 * Get Controller Instance By name.
	 * @param String $controllerName
	 * @throws ControllerFactoryException
	 * @return BaseController.
	 */
	public static function instance($controllerName){
		$name = $controllerName . ControllerFactory::PREFIX;
		$path = Config::CONTROLLER_FOLDER . Config::SLASH . $name . '.php';
		if(file_exists($path)){
			include_once $path;
			if(class_exists($name)){
				return new $name;	
			}
			else{
				throw new ControllerFactoryException('Class '.$name.' not found!');
				return null;
			}
		}
		else{
			throw new ControllerFactoryException('Controller file not found!');
			return null;
		}
	}
}

?>